#include<stdio.h>
#include<stdlib.h>

int cmp_int(const void *a, const void *b)
{
    int arg1 = *(const int*)a;
    int arg2 = *(const int*) b;
    return (arg1>arg2) - (arg1<arg2);
}

int** threeSum(int* nums, int numsSize, int* returnSize, int** returnColumnSizes)
{
    qsort(nums, numsSize,sizeof(int),cmp_int);
    const int NUM = numsSize*numsSize;
    int** res = (int**)malloc(sizeof(int*)*NUM);
    *returnSize = 0;
    *returnColumnSizes = (int*)malloc(sizeof(int)*NUM);
    for(int i = 0;i<numsSize && nums[i]<=0;)
    {
        int l = i+1, r = numsSize-1;
        while(l<r)
        {
            if(!(nums[i]+nums[l]+nums[r]))
            {
                int* ans = (int*)malloc(sizeof(int)*3);
                ans[0] = nums[i]; ans[1] = nums[l]; ans[2] = nums[r];
                res[*returnSize] = ans;
                (*returnColumnSizes)[*returnSize] = 3;
                (*returnSize)++;
                do{r--;}while(l<r && nums[r]==nums[r+1]);
                do{l++;}while(l<r && nums[l]==nums[l-1]);
            }
            else if(nums[i]+nums[l]+nums[r]>0)
            {
                do{r--;}while(l<r && nums[r]==nums[r+1]);
            }
            else 
            {
                do{l++;}while(l<r && nums[l]==nums[l-1]);
            }
        }
        do{i++;}while(i<numsSize&&nums[i-1]==nums[i]);
    }
    return res;
}

int main(int argc, char const *argv[])
{
    freopen("./medium/test.txt","r",stdin);
    const int NUM = 100;
    int arr[NUM];
    int N; scanf("%d",&N);
    for(int i=0;i<N;++i)scanf("%d",arr+i);
    int returnSize;
    int* colsize;
    int** res = threeSum(arr,N,&returnSize,&colsize);
    for(int i = 0; i < returnSize;++i)
    {
        for(int j = 0;j<colsize[i];++j)
        {
            printf("%d ", (*(res+i))[j]);
        }
        printf("\n");
    }
    return 0;
}
